<?php
/**
 * @package YARBB
 * @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * YARBB! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
 */
// no direct access
defined( '_VALID_MOS' ) or die();


// запрещаем гостям смотреть профили
if ($yarbb_user['is_guest']) {
	mosRedirect(sefRelToAbs(YARBB_URL), _NOT_AUTH);
}

$action = isset($_GET['action']) ? $_GET['action'] : null;
$section = isset($_GET['section']) ? $_GET['section'] : null;

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 2) {
	mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
}

if ($yarbb_user['g_read_board'] == '0' && ($action != 'change_pass' || !isset($_GET['key'])))
	mosRedirect(sefRelToAbs(YARBB_URL), _NOT_AUTH);

if ($section == 'ignore') {
	if ($yarbb_user['is_guest'])
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
	//confirm_referrer('profile.php');
	$database->setQuery('SELECT id FROM #__forum_users WHERE id>1');
	$rows=$database->loadRowList();
	foreach ($rows as $row)
		list($valid_ids[]) = $row ;
	// Remove user's own id from list of valid ids (can't ignore yourself)
	$valid_ids = array_diff($valid_ids, array($yarbb_user['id']));
	$ignored_users = explode(",", $yarbb_user['ignored_users']);
	if (in_array($id, $ignored_users))
		$ignored_users = array_diff($ignored_users, array("$id"));
	else
		$ignored_users[] = $id;
	// Scrub ignored user list so it only contains valid user ids
	$ignored_users = array_intersect($ignored_users, $valid_ids);
	// Check length (if you have increased DB field beyond default VARCHAR(255), increase this to match)
	if (strlen(trim(implode(",",$ignored_users), ",")) > 254)
		mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=profile&amp;section=display&amp;id='.$yarbb_user['id']), _Y_IGNORFULL);
	$database->setQuery('UPDATE #__forum_users SET ignored_users=\''.trim(implode(",",$ignored_users), ",").'\' WHERE id='.$yarbb_user['id']);
	$database->query();
	mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=profile&amp;section=display&amp;id='.$yarbb_user['id']), _Y_IGNORUPD);
}
else if (isset($_POST['update_group_membership'])) {
	if ($yarbb_user['g_id'] > YARBB_ADMIN)
		mosRedirect(sefRelToAbs(YARBB_URL), _NOT_AUTH);
	//confirm_referrer('profile.php');
	$new_group_id = intval($_POST['group_id']);
	$database->setQuery('UPDATE #__forum_users SET group_id='.$new_group_id.' WHERE id='.$id);
	$database->query();
	// If the user was a moderator or an administrator, we remove him/her from the moderator list in all forums as well
	if ($new_group_id > YARBB_MOD) {
		$result = $database->setQuery('SELECT id, moderators FROM #__forum_forums');
		$rows= $database->loadAssocList();

		foreach ($rows as $cur_forum ) {
			$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
			if (in_array($id, $cur_moderators)) {
				$username = array_search($id, $cur_moderators);
				unset($cur_moderators[$username]);
				$cur_moderators = (!empty($cur_moderators)) ? '\''.$database->getEscaped(serialize($cur_moderators)).'\'' : 'NULL';
				$database->setQuery('UPDATE #__forum_forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']) ;
				$database->query();
			}
		}
	}
	mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=profile&amp;section=admin&amp;id='.$id), _E_ITEM_SAVED);
}
else if (isset($_POST['update_forums'])) {
	if ($yarbb_user['g_id'] > YARBB_ADMIN)
		mosRedirect(sefRelToAbs(YARBB_URL), _NOT_AUTH);
	//confirm_referrer('profile.php');
	// Get the username of the user we are processing
	$database->setQuery('SELECT username FROM #__forum_users WHERE id='.$id);
	$username = $database->loadResult();
	$moderator_in = (isset($_POST['moderator_in'])) ? array_keys($_POST['moderator_in']) : array();
	// Loop through all forums
	$database->setQuery('SELECT id, moderators FROM #__forum_forums');
	$rows= $database->loadAssocList();

	foreach ($rows as $cur_forum ) {
		$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
		// If the user should have moderator access (and he/she doesn't already have it)
		if (in_array($cur_forum['id'], $moderator_in) && !in_array($id, $cur_moderators)) {
			$cur_moderators[$username] = $id;
			ksort($cur_moderators);
			$database->setQuery('UPDATE #__forum_forums SET moderators=\''.$database->getEscaped(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']);
			$database->query();
		}
		// If the user shouldn't have moderator access (and he/she already has it)
		else if (!in_array($cur_forum['id'], $moderator_in) && in_array($id, $cur_moderators)) {
			unset($cur_moderators[$username]);
			$cur_moderators = (!empty($cur_moderators)) ? '\''.$database->getEscaped(serialize($cur_moderators)).'\'' : 'NULL';
			$database->setQuery('UPDATE #__forum_forums SET moderators='.$cur_moderators.' WHERE id='.$cur_forum['id']);
			$database->query();
		}
	}
	mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=profile&amp;section=admin&amp;id='.$id), _Y_PERMMODUPDATE);
}
else if (isset($_POST['ban'])) {
	if ($yarbb_user['g_id'] > YARBB_MOD || ($yarbb_user['g_id'] == YARBB_MOD && $yarbb_config['p_mod_ban_users'] == '0'))
		mosRedirect(sefRelToAbs(YARBB_URL), _NOT_AUTH);
	mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=admin_bans&amp;add_ban='.$id), _E_ITEM_SAVED);
}
else if (isset($_POST['form_sent'])) {
	// Fetch the user group of the user we are editing
	$database->setQuery('SELECT group_id FROM #__forum_users WHERE id='.$id);
	$database->query();
	if (!$database->getNumRows())
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
	$group_id = $database->loadResult();
	if ($yarbb_user['id'] != $id &&
			($yarbb_user['g_id'] > YARBB_MOD ||
					($yarbb_user['g_id'] == YARBB_MOD && $yarbb_config['p_mod_edit_users'] == '0') ||
					($yarbb_user['g_id'] == YARBB_MOD && $group_id < YARBB_GUEST)))
		mosRedirect(sefRelToAbs(YARBB_URL), _NOT_AUTH);
	//if ($yarbb_user['g_id'] < YARBB_GUEST)

	// Extract allowed elements from $_POST['form']
	function extract_elements($allowed_elements) {
		$form = array();
		reset($_POST['form']);
		while (list($key, $value) = @each($_POST['form'])) {
			if (in_array($key, $allowed_elements))
				$form[$key] = $value;
		}
		return $form;
	}
	$username_updated = false;
	// Validate input depending on section
	switch ($section) {

		case 'display': {
				$form = extract_elements(array('disp_topics', 'disp_posts', 'show_smilies', 'show_img', 'show_img_sig', 'reverse_posts', 'show_avatars', 'show_sig', 'style'));
				$form['reputation_enable'] = yarbb_linebreaks(trim($_POST['reputation_enable']));
				if (!isset($form['reputation_enable']) || $form['reputation_enable'] != '1') $form['reputation_enable'] = '0';
				if ($form['disp_topics'] != '' && intval($form['disp_topics']) < 3) $form['disp_topics'] = 3;
				if ($form['disp_topics'] != '' && intval($form['disp_topics']) > 75) $form['disp_topics'] = 75;
				if ($form['disp_posts'] != '' && intval($form['disp_posts']) < 3) $form['disp_posts'] = 3;
				if ($form['disp_posts'] != '' && intval($form['disp_posts']) > 75) $form['disp_posts'] = 75;
				if (!isset($form['show_smilies']) || $form['show_smilies'] != '1') $form['show_smilies'] = '0';
				if (!isset($form['show_img']) || $form['show_img'] != '1') $form['show_img'] = '0';
				if (!isset($form['show_img_sig']) || $form['show_img_sig'] != '1') $form['show_img_sig'] = '0';
				if (!isset($form['reverse_posts']) || $form['reverse_posts'] != '1') $form['reverse_posts'] = '0';
				if (!isset($form['show_avatars']) || $form['show_avatars'] != '1') $form['show_avatars'] = '0';
				if (!isset($form['show_sig']) || $form['show_sig'] != '1') $form['show_sig'] = '0';

				break;
			}
		case 'privacy': {
				$form = extract_elements(array('email_setting', 'notify_with_post', 'email_alert', 'ignore_mode'));
				$form['email_setting'] = intval($form['email_setting']);
				if ($form['email_setting'] < 0 && $form['email_setting'] > 2) $form['email_setting'] = 1;
				if (!isset($form['notify_with_post']) || $form['notify_with_post'] != '1') $form['notify_with_post'] = '0';
				if (!isset($form['email_alert']) || $form['email_alert'] != '1') $form['email_alert'] = '0';
				if ($form['ignore_mode'] < 0 && $form['ignore_mode'] > 2) $form['ignore_mode'] = 2;

				break;
			}
		default:
			mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
	}
	// Singlequotes around non-empty values and NULL for empty values
	$temp = array();
	while (list($key, $input) = @each($form)) {
		$value = ($input !== '') ? '\''.$database->getEscaped($input).'\'' : 'NULL';
		$temp[] = $key.'='.$value;
	}
	if (empty($temp))
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
	$database->setQuery('UPDATE #__forum_users SET '.implode(',', $temp).' WHERE id='.$id);
	$database->query();
	// If we changed the username we have to update some stuff
	if ($username_updated) {
		$database->setQuery('UPDATE #__forum_posts SET poster=\''.$database->getEscaped($form['username']).'\' WHERE poster_id='.$id) ;
		$database->query();
		$database->setQuery('UPDATE #__forum_topics SET poster=\''.$database->getEscaped($form['username']).'\' WHERE poster=\''.$database->getEscaped($old_username).'\'');
		$database->query();
		$database->setQuery('UPDATE #__forum_topics SET last_poster=\''.$database->getEscaped($form['username']).'\' WHERE last_poster=\''.$database->getEscaped($old_username).'\'');
		$database->query();
		$database->setQuery('UPDATE #__forum_forums SET last_poster=\''.$database->getEscaped($form['username']).'\' WHERE last_poster=\''.$database->getEscaped($old_username).'\'');
		$database->query();
		$database->setQuery('UPDATE #__forum_online SET ident=\''.$database->getEscaped($form['username']).'\' WHERE ident=\''.$database->getEscaped($old_username).'\'');
		$database->query();
		// If the user is a moderator or an administrator we have to update the moderator lists
		$database->setQuery('SELECT group_id FROM #__forum_users WHERE id='.$id);
		$group_id = $database->loadResult();
		if ($group_id < YARBB_GUEST) {
			$database->setQuery('SELECT id, moderators FROM #__forum_forums');
			$rows=$database->loadAssocList();

			foreach ($rows as $cur_forum ) {
				$cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
				if (in_array($id, $cur_moderators)) {
					unset($cur_moderators[$old_username]);
					$cur_moderators[$form['username']] = $id;
					ksort($cur_moderators);
					$database->setQuery('UPDATE #__forum_forums SET moderators=\''.$database->getEscaped(serialize($cur_moderators)).'\' WHERE id='.$cur_forum['id']);
					$database->query();
				}
			}
		}
	}
	mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=profile&amp;section='.$section.'&amp;id='.$id), _Y_RANUPD);
}
$database->setQuery('SELECT u.id, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.show_smilies, u.show_img, u.username, u.reverse_posts, u.show_img_sig, u.show_avatars, u.show_sig, u.num_posts, u.last_post, u.admin_note, g.g_id, g.g_user_title FROM #__forum_users AS u LEFT JOIN #__forum_groups AS g ON g.g_id=u.group_id WHERE u.id='.$id);
$database->query();
if (!$database->getNumRows())
	mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
$rows=$database->loadAssocList();

$user = $rows[0];//$db->fetch_assoc($result);
$last_post = format_time($user['last_post']);

if ((!$section AND !$_GET['plugin']) || $section == 'display') {
	echo $mainframe->setPageTitle( _Y_DISPLAY.' - '.yarbb_htmlspecialchars($yarbb_config['o_board_title']));
	require $yarbb_path.'/task/header.php';
	generate_profile_menu('display');
	?>

<div class="blockform">
	<h2><span><?php echo yarbb_htmlspecialchars($user['username']).' - '._Y_DISPLAY ?></span></h2>
	<div class="box">
		<form id="profile5" method="post" action="<?php echo YARBB_URL ?>&amp;task=profile&amp;section=display&amp;id=<?php echo $id ?>">
			<div>
				<input type="hidden" name="form_sent" value="1" />
			</div>
			<div class="inform">
				<fieldset>
					<legend><?php echo _Y_DISPLAY; ?></legend>
					<div class="infldset">
						<p><?php echo _Y_POSTDISPINF; ?></p>
						<div class="rbox">
							<label>
								<input type="checkbox" name="form[show_smilies]" value="1"<?php if ($user['show_smilies'] == '1') echo ' checked="checked"' ?> />
	<?php echo _Y_PROFSMYLE; ?><br />
							</label>
							<label>
								<input type="checkbox" name="form[show_sig]" value="1"<?php if ($user['show_sig'] == '1') echo ' checked="checked"' ?> />
	<?php echo _Y_SHOWSIGUSR; ?><br />
							</label>
	<?php if ($yarbb_config['o_avatars'] == '1'): ?>
							<label>
								<input type="checkbox" name="form[show_avatars]" value="1"<?php if ($user['show_avatars'] == '1') echo ' checked="checked"' ?> />
		<?php echo _Y_SHOWAVUSR; ?><br />
							</label>
	<?php endif; ?>
							<label>
								<input type="checkbox" name="form[show_img]" value="1"<?php if ($user['show_img'] == '1') echo ' checked="checked"' ?> />
	<?php echo _Y_SHOWIMGPOST; ?><br />
							</label>
							<label>
								<input type="checkbox" name="form[show_img_sig]" value="1"<?php if ($user['show_img_sig'] == '1') echo ' checked="checked"' ?> />
	<?php echo _Y_SHOIMGSIG; ?><br />
							</label>
						</div>
						<p><?php echo _Y_MYREVPOST; ?></p>
						<div class="rbox">
							<label>
								<input type="checkbox" name="form[reverse_posts]" value="1"<?php if ($user['reverse_posts'] == '1') echo ' checked="checked"' ?> />
									<?php echo _Y_MYREVPOST2; ?><br />
							</label>
						</div>
					</div>
				</fieldset>
			</div>
			<div class="inform">
				<fieldset>
					<legend><?php echo _Y_VIEWTOPDISP; ?></legend>
					<div class="infldset">
						<p class="clearb"><?php echo _Y_PAGINATEINFO; ?> <?php echo _Y_PAGINATEINFO2 ?></p>
						<label class="conl"><?php echo _Y_TOPIC_PAGE; ?><br />
							<input type="text" name="form[disp_topics]" value="<?php echo $user['disp_topics'] ?>" size="6" maxlength="3" />
							<br />
						</label>
						<label class="conl"><?php echo _Y_POSTPAGE; ?><br />
							<input type="text" name="form[disp_posts]" value="<?php echo $user['disp_posts'] ?>" size="6" maxlength="3" />
							<br />
						</label>
					</div>
				</fieldset>
			</div>
			<p>
				<input type="submit" name="update" value="<?php echo _SAVE; ?>" />
			</p>
		</form>
	</div>
</div>
	<?php
}
else if ($section == 'privacy') {
	echo $mainframe->setPageTitle( _Y_PRIVOPT.' - '.yarbb_htmlspecialchars($yarbb_config['o_board_title']));
	require $yarbb_path.'/task/header.php';
	generate_profile_menu('privacy');
	?>
<div class="blockform">
	<h2><span><?php echo yarbb_htmlspecialchars($user['username']).' - '._Y_PRIVOPT; ?></span></h2>
	<div class="box">
		<form id="profile6" method="post" action="<?php echo YARBB_URL ?>&amp;task=profile&amp;section=privacy&amp;id=<?php echo $id ?>">
			<div class="inform">
				<fieldset>
					<legend><?php echo _Y_PRIVOPT; ?></legend>
					<div class="infldset">
						<input type="hidden" name="form_sent" value="1" />
						<p><?php echo _Y_PRIVINFO; ?></p>
						<div class="rbox">
							<label>
								<input type="radio" name="form[email_setting]" value="0"<?php if ($user['email_setting'] == '0') echo ' checked="checked"' ?> />
	<?php echo _Y_PRIVEMAIL1; ?><br />
							</label>
							<label>
								<input type="radio" name="form[email_setting]" value="1"<?php if ($user['email_setting'] == '1') echo ' checked="checked"' ?> />
	<?php echo _Y_PRIVEMAIL2; ?><br />
							</label>
							<label>
								<input type="radio" name="form[email_setting]" value="2"<?php if ($user['email_setting'] == '2') echo ' checked="checked"' ?> />
	<?php echo _Y_PRIVEMAIL3; ?><br />
							</label>
						</div>
						<p><?php echo _Y_PRIVNOTINF; ?></p>
						<div class="rbox">
							<label>
								<input type="checkbox" name="form[notify_with_post]" value="1"<?php if ($user['notify_with_post'] == '1') echo ' checked="checked"' ?> />
	<?php echo _Y_PRIVNOTF; ?><br />
							</label>
						</div>
						<p><?php echo _Y_PRIVPMS2; ?></p>
						<div class="rbox">
							<label>
								<input type="checkbox" name="form[email_alert]" value="1"<?php if ($user['email_alert'] == '1') echo ' checked="checked"' ?> />
	<?php echo _Y_PRIVPMS; ?><br />
							</label>
						</div>
					</div>
				</fieldset>
			</div>
			<div class="inform">
				<fieldset>
					<legend><?php echo _Y_PRIVIGN; ?></legend>
					<div class="infldset">
						<div class="rbox">
							<label>
								<input type="radio" name="form[ignore_mode]" value="0"<?php if ($yarbb_user['ignore_mode'] == '0') echo ' checked="checked"' ?> />
	<?php echo _Y_PRIVIGN1; ?> <br />
							</label>
							<label>
								<input type="radio" name="form[ignore_mode]" value="1"<?php if ($yarbb_user['ignore_mode'] == '1') echo ' checked="checked"' ?> />
	<?php echo _Y_PRIVIGN2; ?> <br />
							</label>
							<label>
								<input type="radio" name="form[ignore_mode]" value="2"<?php if ($yarbb_user['ignore_mode'] == '2') echo ' checked="checked"' ?> />
	<?php echo _Y_PRIVIGN3; ?> <br />
							</label>
						</div>
					</div>
				</fieldset>
			</div>
			<p>
				<input type="submit" name="update" value="<?php echo _SAVE; ?>" />
				<br />
	<?php // Gather ignore data
	$ignore_set = array();
	$database->setQuery('SELECT id, username, ignore_mode, ignored_users FROM #__forum_users WHERE id>1');
	$rows=$database->loadAssocList();

	foreach($rows as $row)
		$ignore_set[$row['id']] = array("username" => $row['username'], "ignore_mode" => $row['ignore_mode'], "ignored_users" => $row['ignored_users'], "ignored_by_count" => 0);

	?>
			<div class="inform">
				<fieldset>
					<legend><?php echo _Y_IGNORNOW; ?></legend>
					<div class="infldset">
									<?php if ($yarbb_user['ignored_users']): ?>
						<label>
		<?php echo _Y_IGNORNOW2; ?><br />
							<p>
										<?php $j = 0;
		foreach (explode(",", $yarbb_user['ignored_users']) as $ignid) {
			if (++$j != 1)
				echo ', ';
			echo '<a href="'.sefRelToAbs('index.php?option=com_users&task=profile&amp;user='.$ignid).'">'.yarbb_htmlspecialchars($ignore_set[$ignid]['username']).'</a>';
		} ?>
							</p>
							<br />
						</label>
					<?php else: ?>
						<label><?php echo _Y_BANNONE; ?><br />
						</label>
					<?php endif; ?>
					</div>
				</fieldset>
			</div>
					<?php if (TRUE): // set to FALSE to disable "most ignored" list ?>
			<div class="inform">
		<?php // Calculate, trim, sort, and retrim ignore data
		$ignore_row = array();
		foreach ($ignore_set as $ignore_row)
			if ($ignore_row['ignored_users'] && $ignore_row['ignore_mode'] != 0)
										foreach (explode(",", $ignore_row['ignored_users']) as $ignid)
					++$ignore_set[$ignid]['ignored_by_count'];
									$ignore_table = array();
		foreach ($ignore_set as $ignid => $ignore_row)
											if ($ignore_row['ignored_by_count'] != 0)
												$ignore_table[$ignid] = $ignore_row['ignored_by_count'];
										arsort($ignore_table, SORT_NUMERIC);
										if (count($ignore_table) > 10)
											$ignore_table = array_slice($ignore_table, 0, 10, TRUE);
										?>
				<fieldset>
					<legend><?php echo _Y_IGNTOP10; ?></legend>
					<div class="infldset">
						<table width="100%" cellspacing="0">
							<thead>
								<tr>
									<th class="tcl" scope="col"><?php echo _UNAME; ?></th>
									<th class="tc2" scope="col"><?php echo _Y_IGNUSER; ?></th>
								</tr>
							</thead><tbody>
					<?php foreach ($ignore_table as $ignid => $ignore_count): ?>

								<tr>
									<td class="tcl"><?php echo '<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=profile&amp;id='.$ignid).'">'.yarbb_htmlspecialchars($ignore_set[$ignid]['username']).'</a>' ?></td>
									<td class="tc2"><?php echo $ignore_count ?></td>
								</tr>

						<?php endforeach; ?></tbody>
						</table>
					</div>
				</fieldset>
			</div>
					<?php endif; ?>
		</form>
	</div>
</div>
	<?php
}

else if ($section == 'admin') {
	if ($yarbb_user['g_id'] > YARBB_MOD || ($yarbb_user['g_id'] == YARBB_MOD && $yarbb_config['p_mod_ban_users'] == '0'))
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);

	echo $mainframe->setPageTitle( _Y_YARMODERS.' - '.yarbb_htmlspecialchars($yarbb_config['o_board_title']));

	require $yarbb_path.'/task/header.php';
									generate_profile_menu('admin');
	?>
<div class="blockform">
	<h2><span><?php echo yarbb_htmlspecialchars($user['username']).' - '._Y_PROBUN; ?></span></h2>
	<div class="box">
		<form id="profile7" method="post" action="<?php echo YARBB_URL ?>&amp;task=profile&amp;section=admin&amp;id=<?php echo $id ?>&amp;action=foo">
			<div class="inform">
				<input type="hidden" name="form_sent" value="1" />
				<fieldset>
	<?php
	if ($yarbb_user['g_id'] == YARBB_MOD) {
		?>
					<legend><?php echo _Y_PROBUN; ?></legend>
					<div class="infldset">
						<p>
							<input type="submit" name="ban" value="<?php echo _Y_PROBUN; ?>" />
						</p>
					</div>
				</fieldset>
			</div>
		<?php
	}
	else {
		if ($yarbb_user['id'] != $id) {
			?>
			<legend><?php echo _Y_PROGROUP; ?></legend>
			<div class="infldset">
				<fieldset>
					<select id="group_id" name="group_id">
			<?php
			$database->setQuery('SELECT g_id, g_title FROM #__forum_groups WHERE g_id!='.YARBB_GUEST.' ORDER BY g_title');
			$rows=$database->loadAssocList();

			foreach($rows as $cur_group ) {
				if ($cur_group['g_id'] == $user['g_id'] || ($cur_group['g_id'] == $yarbb_config['o_default_user_group'] && $user['g_id'] == ''))
					echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.yarbb_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
									else
										echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.yarbb_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
								}
								?>
					</select>
					<input type="submit" name="update_group_membership" value="<?php echo _SAVE; ?>" />

				</fieldset></div>
			<div class="inform">
				<fieldset>
			<?php
		}
					?>
					<legend><?php echo _Y_PROBUN; ?></legend>
					<div class="infldset">
						<input type="submit" name="ban" value="<?php echo _Y_PROBUN; ?>" />
					</div>
				</fieldset>
			</div>
		<?php
		if ($user['g_id'] == YARBB_MOD || $user['g_id'] == YARBB_ADMIN) {
			?>
			<div class="inform">
				<fieldset>
					<legend><?php echo _Y_INSTMODERPERM; ?></legend>
					<div class="infldset">
						<p><?php echo _Y_INSTMODERPERM2; ?></p>
									<?php
									$database->setQuery('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.moderators FROM #__forum_categories AS c INNER JOIN #__forum_forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position');
									$cur_category = 0;
									$rows=$database->loadAssocList();

									foreach ($rows as $cur_forum ) {
										if ($cur_forum['cid'] != $cur_category)	// A new category since last iteration?
				{
					if ($cur_category)
						echo "\n\t\t\t\t\t\t\t\t".'</div>';
					if ($cur_category != 0)
						echo "\n\t\t\t\t\t\t\t".'</div>'."\n";
					echo "\t\t\t\t\t\t\t".'<div class="conl">'."\n\t\t\t\t\t\t\t\t".'<p><strong>'.$cur_forum['cat_name'].'</strong></p>'."\n\t\t\t\t\t\t\t\t".'<div class="rbox">';
										$cur_category = $cur_forum['cid'];
									}
									$moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
				echo "\n\t\t\t\t\t\t\t\t\t".'<label><input type="checkbox" name="moderator_in['.$cur_forum['fid'].']" value="1"'.((in_array($id, $moderators)) ? ' checked="checked"' : '').' />'.yarbb_htmlspecialchars($cur_forum['forum_name']).'<br /></label>'."\n";
			}
			?></div>

					<br class="clearb" />
					<input type="submit" name="update_forums" value="<?php echo _SAVE; ?>" />

				</fieldset>
			</div>
						<?php
		}
	}
	?>
		</form>
	</div>
</div>
							<?php
						}

						?>
<div class="clearer"></div>
</div>
